const router = require('koa-router')();
const path = require('path');
const DB = require('../module/db');
router.post('/dl')


router.post('/', async (ctx, next) => {
    let MongoClient = require('mongodb').MongoClient;
    let Url = 'mongodb://127.0.0.1:27017';
                let req = ctx.request.body;
                let time = new Date();
                time = time.toLocaleDateString();
                let mydate = {
                    uname: req.uname,
                    upassword: req.upassword,
                    };
        let res = await DB.find('users',mydate);
        if(res.length==0){
            console.log('查询失败')
            let date = {
                uname: req.uname,
                upassword: req.upassword,
                unickname: '',
                uid: Math.random()*10000+10000+'',
                ulevel: 0,
                usex: '',
                uphone: '',
                uemail: '',
                ukey: '',
                uage: 0,
                urtime: time,
                // ultime: ''
            }
            let res1 = await DB.insert('users',date);
            if(res1){
                ctx.body=[{
                    err:true,
                    uname:req.uname,
                    uid:date.uid

                }]
            }
        }else{
            ctx.body=res
        }
})
module.exports = router.routes()
